/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.proteu.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author eros
 */
public class IOUtils {


     public static String getStringFromFile(String filename){

        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();
        try{
            br = new BufferedReader(new FileReader(filename));
            try{
                String s;
                while((s = br.readLine()) != null){
                    //System.out.println(s);
                    sb.append(s+"\n");
                    //sb.append("\n");
                }
            }catch(IOException xcp){
                System.err.println(xcp);
            }finally{
                br.close();
            }
        }catch(IOException xcp){
            xcp.printStackTrace();
        }

        return sb.toString();
    }

  public static boolean saveStringToFile(String filename,String stringStream){
        boolean save = false;
        BufferedWriter bw = null;
        try{
            bw = new BufferedWriter(new FileWriter(filename));
            try{
                bw.write(stringStream);
                save = true;
            }catch(IOException xcp){
                System.err.println(xcp);
            }finally{
                bw.close();
            }
        }catch(IOException xcp){
            System.err.println(xcp);
        }

        return save;
    }

}
